package com.atguigu.linklist;

import java.util.HashSet;
import java.util.Set;

public class TheRingOfListnode {
    public static ListNode findTheEntranceOfRing(ListNode head){
        if(head==null) return null;
        if(head.next==null) return head;
        Set<ListNode> set=new HashSet<>();
        ListNode cur=head;
        while(cur!=null){
            if(set.contains(cur)){
                return cur;
            }else{
                set.add(cur);
                cur=cur.next;
            }
        }
        return null;
    }
}
